"""
    UI lookup for audit table. Only for internal usage.
"""

import turbogears
from mnemoply import model
from mnemoply.controllers.lookup import LookupController, TableCol, TableLookupDataSource
from mnemoply.controllers.containers import ModelObjectContainer
from mnemoply.utils import LocalMenuItem

class AuditChangesController(LookupController, ModelObjectContainer):
    lookup_columns = [
        TableCol(name='timestamp', caption="Time"),
        TableCol(name='action_url', caption="URL"),
        TableCol(name='transaction_id', caption="Trn#", size=3, hidden=True),
        TableCol(name='user_name', caption="User", size=6),
        TableCol(name='kind', caption="Kind", size=2),
        TableCol(name='object_id', caption="Obj#", size=3, hidden=True),
        TableCol(name='object_title', caption="ObjTitle", size=5),
        TableCol(name='object_class_name', caption="ObjClass", size=5),
        TableCol(name='details', caption="Details"),
    ]

    def __init__(self):
        ModelObjectContainer.__init__(self, model.AuditChange)
        LookupController.__init__(self,
            data_source=TableLookupDataSource("audit_changes_lookup"),
            columns=self.lookup_columns,
            title="Audit: database changes",
        )
        self.object_local_menu = [LocalMenuItem(caption=_('List'), href='../list')]

    @turbogears.expose(template="genshi:mnemoply.templates.audit_change_show")
    def show(self, obj):
        return dict(obj=obj)

exposed = turbogears.identity.SecureObject(AuditChangesController(), turbogears.identity.has_permission('dba'))
